#pragma once
#include "Dllexport.h"
#include "Exception.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#pragma comment(lib,"freetype249.lib")
#include "RendererBase.h"
#include <map>
namespace NBGUI
{
	struct strDrawingPack
	{
		strDrawingPack():
		start(0),len(0)
		{}
		strDrawingPack(unsigned int s,unsigned int l):
			start(s),len(l)
		{}

		unsigned int start;
		unsigned int len;
	};

	struct GUIAPI CharInfo 
	{
		char ch;
		vec2f uv[4];//uv in a single tile
		unsigned int inedx;//the index in the big texture, to cal the real uv
		int adv_x,adv_y;
		int size_x,size_y;//bitmap size
		FT_Pos offsetBearing;
	};

	class GUIAPI Font
	{
	public:
		Font(const char* fontPath, RendererBase* renderer ,unsigned int h, unsigned int device_w, unsigned int device_h );
		~Font()
		{
			//delete[] texArray;
			delete[] expanded_data;
		}

		void packCharacter( char ch, int idx, int charCount );
		void calculateCharWH( char ch);

		strDrawingPack addText(const char* str, float x, float y, float size);//add the quads
		void initDrawing();
		void drawStrPack(strDrawingPack& pack);

	private:
		FT_Library library;
		FT_Face face;
		unsigned int h;

		//unsigned int* texArray;
		RendererBase* pRenderer;

		//for the biggest character, using this for every char
		int width_char;
		int height_char;
		byte* expanded_data;
		int texNum;//the size of textures on the edge
		int fontTexId;

		std::vector<Vertex> vertices;
		std::vector<unsigned int> indices;
		int vboId;
		int iboId;

		std::map<char,CharInfo> charMap;

	};




}